home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / cgterm10.zip / CGTERM.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-01  |  11KB  |  317 lines

  1. (*$C-,U-,R-,V-,K-*)
  2. PROGRAM DumbTrm;
  3.  
  4. (*--------------------------------------------------------------------------*)
  5. (*                                                                          *)
  6. (*   Program:   DumbTrm                                                     *)
  7. (*                                                                          *)
  8. (*   Author:    Philip R. Burns                                             *)
  9. (*                                                                          *)
  10. (*   Date:      November 1, 1986                                            *)
  11. (*                                                                          *)
  12. (*   Purpose:   Dumb terminal emulator to demonstrate PibAsync routines.    *)
  13. (*                                                                          *)
  14. (*   Usage:     Compile to .COM file using Turbo Pascal and execute the     *)
  15. (*              .COM file by typing  DUMBTRM  at the DOS prompt.            *)
  16. (*                                                                          *)
  17. (*              You will be prompted for the required communications        *)
  18. (*              parameters.  If the serial port can be opened successfully, *)
  19. (*              then a dumb terminal mode is entered.                       *)
  20. (*                                                                          *)
  21. (*              To exit dumb terminal mode, type ^C (ascii 03).  To send    *)
  22. (*              a break, type ^B (ascii 02).                                *)
  23. (*                                                                          *)
  24. (*   Needs:     See includes below for files included from PibAsync.Arc.    *)
  25. (*                                                                          *)
  26. (*   Remarks:   This program doesn't check for input mistakes when the      *)
  27. (*              communications parameters are being entered.                *)
  28. (*                                                                          *)
  29. (*--------------------------------------------------------------------------*)
  30.  
  31. (*$I GLOBTYPE.GLO *)
  32. (*$I ASCII.GLO    *)
  33.  
  34. VAR
  35.    Baud_Rate   : INTEGER           (* Baud rate for connection, e.g., 1200  *);
  36.    Com_Port    : INTEGER           (* Which port, e.g., 1 for COM1:         *);
  37.    Parity      : CHAR              (* Parity, e.g., E for even parity       *);
  38.    Data_Bits   : INTEGER           (* How many bits per character, e.g., 8  *);
  39.    Stop_Bits   : INTEGER           (* How many stop bits -- nearly always 1 *);
  40.  
  41. VAR
  42.    InBufSize   : INTEGER           (* Size of input buffer                  *);
  43.    OutBufSize  : INTEGER           (* Size of output buffer                 *);
  44.    Do_XonXoff  : CHAR              (* 'Y' to do XON/XOFF flow control       *);
  45.    Do_HardWired: CHAR              (* 'Y' to do XON/XOFF flow control       *);
  46.    Do_CTS      : CHAR              (* 'Y' to do CTS checking                *);
  47.    Do_DSR      : CHAR              (* 'Y' to do DSR checking                *);
  48.  
  49. (*$I PIBASYNC.GLO *)
  50. (*$I PIBASYN1.MOD *)
  51. (*$I PIBASYN2.MOD *)
  52. (*$I PIBASYN3.MOD *)
  53.  
  54. (*--------------------------------------------------------------------------*)
  55. PROCEDURE Get_Comm_Params;
  56.  
  57. VAR
  58.    YesNo : CHAR;
  59.  
  60. BEGIN (* Get_Comm_Params *)
  61.    ClrScr;
  62.    textcolor(12);
  63.    WRITE('Com Port  [1,2]     : ');textcolor(11);
  64.    READLN( Com_Port );textcolor(12);
  65.    WRITE('Baud Rate [300-9600]: ');textcolor(11);
  66.    READLN( Baud_Rate );
  67.    Parity := 'N';
  68.    Data_bits:=8;
  69.    Stop_Bits:=1;
  70.    textcolor(15);
  71. END   (* Get_Comm_Params *);
  72.  
  73. (*--------------------------------------------------------------------------*)
  74.  
  75. Procedure baudchange;
  76. var brate:integer;
  77. begin
  78.   textcolor(12);
  79.   write('New Baud Rate: ');readln( baud_rate );
  80.   async_reset_port(com_port,baud_rate,parity,data_bits,stop_bits);
  81. end;
  82.  
  83. procedure skey(c:char);
  84. begin
  85.   case ord(c) of
  86.     59:baudchange;
  87.    end;
  88. end;
  89.  
  90. FUNCTION Initialize_Communications : BOOLEAN;
  91. BEGIN (* Initialize_Communications *)
  92.    Async_Break_Length   := 500;
  93.    Async_Init( InBufSize, OutBufSize, 0, 0, 0);
  94.    IF ( NOT Async_Open( Com_Port, Baud_Rate, Parity, Data_Bits, Stop_Bits ) ) THEN
  95.       BEGIN
  96.          WRITELN('Cannot open serial port.');
  97.          Initialize_Communications := FALSE;
  98.       END
  99.    ELSE
  100.       BEGIN
  101.          WRITELN('Serial port opened, DumbTrm ready.');
  102.          Initialize_Communications := TRUE;
  103.       END;
  104.  
  105. END   (* Initialize_Communications *);
  106.  
  107. (*--------------------------------------------------------------------------*)
  108.  
  109. PROCEDURE Emulate_Dumb_Terminal;
  110.  
  111. VAR
  112.    Kch: CHAR;
  113.    Ch : CHAR;
  114.    cha: integer;
  115.    chs: integer;
  116.    chst: string[1];
  117.  
  118. BEGIN (* Emulate_Dumb_Terminal *)
  119. Clrscr;
  120. window(1,1,80,3);
  121. textcolor(12);
  122. writeln('     Spectrum Commodore C/G Terminal Emulator by Scott Deming v1.00');
  123. textcolor(11);
  124. writeln('══════════════════════════════════════════════════════════════════════════════');
  125. textcolor(15);
  126. window(1,4,80,25);
  127.                                    (* Begin loop over serial port   *)
  128.                                    (* and keyboard.                 *)
  129.    REPEAT
  130.                                    (* Pick up and display character *)
  131.                                    (* from port, if any.            *)
  132.  
  133.       IF Async_Receive( Ch ) THEN
  134.          IF ( Ch <> CHR( 0 ) ) THEN
  135.            case Ch of
  136.               #20:write(#8' '#8);
  137.               #59:skey(#59);
  138.               #28:textcolor(4);
  139.               #30:textcolor(2);
  140.               #31:textcolor(1);
  141.              #144:textcolor(15);
  142.              #156:textcolor(13);
  143.              #158:textcolor(14);
  144.              #159:textcolor(11);
  145.               #18:textbackground(15);
  146.              #146:textbackground(0);
  147.                #5:textcolor(15);
  148.               #13:writeln;
  149.               #15:write(' ');
  150.              #176:write('┌');
  151.              #174:write('┐');
  152.              #173:write('└');
  153.              #189:write('┘');
  154.              #177:write('┴');
  155.              #178:write('┬');
  156.              #179:write('┤');
  157.              #171:write('├');
  158.              #166:write('░');
  159.              #129:textcolor(5);
  160.              #150:textcolor(12);
  161.              #149:textcolor(6);
  162.              #151:textcolor(7);
  163.              #152:textcolor(15);
  164.              #153:textcolor(10);
  165.              #154:textcolor(9);
  166.              #155:textcolor(15);
  167.              #147:clrscr;
  168.              #148:write(#8);
  169.               #10:write;
  170.              #162:write('▄');
  171.              #164:write('_');
  172.              #161:write('▌');
  173.              #180:write('▌');
  174.              #181:write('▌');
  175.              #182:write('▐');
  176.              #175:write('▄');
  177.              #184:write('▀');
  178.              #185:write('▄');
  179.              #183:write('▀');
  180.              #168:write('▄');
  181.              #167:write('▐');
  182.              #165:write('▌');
  183.              #163:write('▀');
  184.              #124:write('▌');
  185.              #125:write('│');
  186.               #96:write('─');
  187.              #123:write('┼');
  188.              #160:write(' ');
  189.              #192:write('─');
  190.              #193:write('A');
  191.              #194:write('B');
  192.              #195:write('C');
  193.              #196:write('D');
  194.              #197:write('E');
  195.              #198:write('F');
  196.              #199:write('G');
  197.              #200:write('H');
  198.              #201:write('I');
  199.              #202:write('J');
  200.              #203:write('K');
  201.              #204:write('L');
  202.              #205:write('M');
  203.              #206:write('N');
  204.              #207:write('O');
  205.              #208:write('P');
  206.              #209:write('Q');
  207.              #210:write('R');
  208.              #211:write('S');
  209.              #212:write('T');
  210.              #213:write('U');
  211.              #214:write('V');
  212.              #215:write('W');
  213.              #216:write('X');
  214.              #217:write('Y');
  215.              #218:write('Z');
  216.              #219:write('┼');
  217.              #220:write('▌');
  218.              #221:write('│');
  219.              #222:write('π');
  220.              #223:write('▄');
  221.              #232:write('▄');
  222.              #188:write('■');
  223.              #190:write('■');
  224.              #191:write('█');
  225.              #186:write('█');
  226.              #187:write('■');
  227.              #172:write('■');
  228.              #127:write('▀');
  229.              #169:write('▀');
  230.              #160:write(' ');
  231.              #233:write('▀');
  232.              #224:write(' ');
  233.              #225:write('▌');
  234.              #226:write('▄');
  235.              #227:write('▀');
  236.              #228:write('▄');
  237.              #229:write('▌');
  238.              #230:write('░');
  239.              #231:write('▐');
  240.              #232:write('▄');
  241.              #233:write('▄');
  242.              #234:write('▐');
  243.              #235:write('├');
  244.              #236:write('▄');
  245.              #237:write('└');
  246.              #238:write('┐');
  247.              #239:write('▄');
  248.              #240:write('┌');
  249.              #241:write('┴');
  250.              #242:write('┬');
  251.              #243:write('┤');
  252.              #244:write('▌');
  253.              #245:write('▌');
  254.              #246:write('▐');
  255.              #247:write('▀');
  256.              #248:write('▀');
  257.              #249:write('▄');
  258.              #250:write('█');
  259.              #251:write('▄');
  260.              #252:write('▀');
  261.              #253:write('┘');
  262.              #254:write('▀');
  263.              #170:write('▐');
  264.             else
  265.            WRITE( Ch );
  266.          end;
  267.                                    (* Read character from keyboard  *)
  268.                                    (* and send out port, unless it  *)
  269.                                    (* is ^B or ^C.                  *)
  270.                                    (* ^B -- send a break            *)
  271.                                    (* ^C -- quit                    *)
  272.       IF KeyPressed THEN
  273.          BEGIN
  274.             READ( Kbd, KCh );
  275.             CASE KCh OF
  276.                ^B: Async_Send_Break;
  277.                ^C: ;
  278.                #8: Async_Send(#20);
  279.                ELSE
  280.                   Async_Send( Kch );
  281.             END (* CASE *);
  282.          END;
  283.  
  284.    UNTIL ( Kch = ^C );
  285.  
  286. END   (* Emulate_Dumb_Terminal *);
  287.  
  288. (*--------------------------------------------------------------------------*)
  289.  
  290. PROCEDURE Finish_Communications;
  291.  
  292. BEGIN (* Finish_Communications *)
  293.                                    (* Close port and drop DTR *)
  294.    Async_Close( TRUE );
  295.                                    (* Release space allocated for buffers *)
  296.    Async_Release_Buffers;
  297.  
  298. END   (* Finish_Communications *);
  299.  
  300. (*--------------------------------------------------------------------------*)
  301.  
  302. BEGIN (* DumbTrm *)
  303.  
  304.                                    (* Request serial port parameters     *)
  305.    Get_Comm_Params;
  306.                                    (* Initialize port                    *)
  307.  
  308.    IF Initialize_Communications THEN
  309.       BEGIN
  310.                                    (* Emulate dumb terminal until ^C hit *)
  311.          Emulate_Dumb_Terminal;
  312.                                    (* Close down port                    *)
  313.          Finish_Communications;
  314.  
  315.       END;
  316.  
  317. END   (* DumbTrm *).